package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.service.wx.WxCollectService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.vo.wx.lhh.AddOrDeleteCollectVo;
import com.cskaoyan.market.vo.wx.lhh.CollectListVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName WxCollectController
 * @Description
 * @Author MZ
 * @Date 2023/5/22 20:19
 */
@RestController
@RequestMapping("wx/collect")
public class WxCollectController {
    @Autowired
    WxCollectService wxCollectService;

    @GetMapping("list")
    public Object list(Byte type, Integer page, Integer limit) {
        // type=0&page=1&limit=10
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        Integer userId = (Integer) session.getAttribute("userId");

        List<CollectListVo> result = wxCollectService.collectList(type, page, limit,userId);

        return ResponseUtil.okList(result);
    }

    @PostMapping("addordelete")
    public Object addordelete(@RequestBody AddOrDeleteCollectVo collectVo){
        // {"type":0,"valueId":1011004}
        Byte type = collectVo.getType();
        Integer valueId = collectVo.getValueId();

        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        Integer userId = (Integer) session.getAttribute("userId");
        wxCollectService.addOrDelete(type, valueId ,userId);

        return ResponseUtil.ok();
    }

}
